class Solution {
    public int countSubstrings(String s) {
        if(s == null || s.length() == 0) {
            return 0;
        }
        int count = 0;
        //字符串的每个字符都作为回文中心进行判断，中心是一个字符或两个字符
        for(int i = 0;i < s.length();i++) {
            count += ss(s,i,i);
            count += ss(s,i,i+1);
        }
        return count;
    }

    private int ss(String s,int left,int right) {
        int count = 0;
        while(left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
            count++;
            left--;
            right++;
        }
        return count;
    }
}